import network from '../../utils/network.js';
Page({
  data: {
    pid:0,
    userInfo: [],
    isHiddenToast: true,
    page: 1,
    rows: 10,
    total: 0,
    hasMoreData: true,
    list: [],  
    Inx: 0
  },
  // 新的绑定导航切换样式方法
  changeTab: function (event) {
    this.setData({
      Inx: event.currentTarget.dataset.index
    })
  },
  isShowToast: function () {
    this.setData({
      isHiddenToast: false
    })
  },


  onLoad: function (options) {
    var that = this;
    const id = options.id;
    that.setData({
      pid:id,
    });
    that.getSale_list('正在加载数据...')
    // 页面初始化 options为页面跳转所带来的参数
  },
  onDetail: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/view/join_data/join_data?id=' + id,
    });
  },
  onGetSaleList: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/view/join_team/join_team?id=' + id,
    });
  },
// 跳转客户列表
  onGetCustomer:function(e){
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/view/member_order/member_order?id=' + id,
    });
  },

  // 获取删除
  onDelete: function (e) {
    var that = this;
    const id = e.currentTarget.dataset.id
    var data = {
      id: id,
    };
    const message = "正在删除中";
    network.requestLoading('http://jbc.com/System/User/manager_delete', data, message, function (res) {
      if (res.code > 0) {
        wx.showToast({
          title: '删除成功',
        });
        that.data.page = 1;
        that.data.list = [];
        that.getSale_list('正在刷新数据')
      } else {
        wx.showToast({
          title: res.msg,
        });
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
// 获取用户列表
  getSale_list: function (message) {
    var that = this;
    const pid = that.data.pid;
    var datas = that.data;
    var data = {
      manager_id: pid,
      ischeck: 1,
      page: datas.page,
      rows: datas.rows
    };
    network.requestLoading('http://jbc.com/System/User/sale_list', data, message, function (res) {
      var contentlistTem = that.data.list;
      if (res.code > 0) {
        if (contentlistTem.length < res.data.total) {
          that.setData({
            page: datas.page + 1,
            list: res.data.list,
          });
        } else {
          that.setData({
            hasMoreData: false
          });
        }

      } else {
        wx.showToast({
          title: res.msg,
        })
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.getSale_list('正在刷新数据')
    console.log("下拉加载更多")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("下滑加载更多")
    if (this.data.hasMoreData) {
      this.getSale_list('加载更多数据');
    } else {
      console.log("没有更多的数据")
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },
})